package com.cotte.flow.hbase.dao;

import java.io.IOException;

import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cotte.flow.hbase.record.TransitRecord;
import com.cotte.flow.hbase.table.TransitStruct;

/**
 * 保存在途时间
* <p>Title: TransitDaoImpl</p>  
* <p>Description: </p>  
* @author YGJ  
* @date 2018年12月5日
 */
@Component
public class TransitDaoImpl {
	
	@Autowired
	private Connection connection;
	
	public void putRecord(TransitRecord transitRecord) {
		Table table = null;
		try{
			table = connection.getTable(TableName.valueOf(TransitStruct.TABLE));
			Put put = new Put((transitRecord.getOdid_stepcode()).getBytes());
			put.addColumn(TransitStruct.FAMILY.getBytes(), TransitStruct.COLUMN_PRE_STEP.getBytes(), transitRecord.getPrestep().getBytes());
			put.addColumn(TransitStruct.FAMILY.getBytes(), TransitStruct.COLUMN_STEPCODE.getBytes(), transitRecord.getStepcode().getBytes());
			put.addColumn(TransitStruct.FAMILY.getBytes(), TransitStruct.COLUMN_TRANSIT.getBytes(), transitRecord.getTransit().getBytes());
			table.put(put);
		}catch(Exception e){
			e.printStackTrace();
		}finally {
			try {
				table.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}